/****************************************************************************
**
** Copyright (C) 2009 Alexander Solis.
**
** This file is part of Alejandria
** Alejandria is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Alejandria is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Alejandria.  If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/

#include <QtGui>

#include "subcategorydelegate.h"

SubCategoryDelegate::SubCategoryDelegate(QObject *parent)
	: QItemDelegate(parent)
{

}

QWidget *SubCategoryDelegate::createEditor (QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
{
	QComboBox *editor = new QComboBox(parent);
	
	QModelIndex categoryIndex = index.model()->index(index.row(), index.column()-1);
	QString categoryValue = index.model()->data(categoryIndex, Qt::EditRole).toString();
	
	if (categoryValue == "Computer science, information & general works") {
        QStringList comboData;
        comboData << "" << "Computer science, knowledge & systems" << "Bibliographies"  << "Library & information sciences"  
                  << "Encyclopedias & books of facts" << "Magazines, journals & serials" << "Associations, organizations & museums"  
                  << "News media, journalism & publishing"  << "Quotations"  << "Manuscripts & rare books";
        editor->clear();
        editor->addItems(comboData);		
	} else if (categoryValue == "Philosophy and psychology") {
        QStringList comboData;
        comboData << "" << "Philosophy & psychology" << "Metaphysics"  << "Epistemology, causation, humankind" << "Paranormal phenomena" 
                  << "Specific philosophical schools" << "Psychology" << "Logic"  << "Ethics (Moral philosophy)"
                  << "Ancient, medieval, Oriental philosophy" << "Modern Western philosophy (19th-century, 20th-century)";
        editor->clear();
        editor->addItems(comboData);		
	} else if (categoryValue == "Religion") {
        QStringList comboData;
        comboData << "" << "Comparative religion" << "Christian" << "Native American" << "Classical (Greek & Roman) religion"  << "Germanic religion"  
                  << "Religions of Indic origin" << "Zoroastrianism (Mazdaism, Parseeism)" << "Judaism"  
                  << "Islam, Bábism & Bahá'í Faith"  << "Mithology"  << "Other religions";
        editor->clear();
        editor->addItems(comboData);		
	} else if (categoryValue == "Social sciences") {
        QStringList comboData;
        comboData << "" << "Social sciences" << "General statistics"  << "Political science" << "Economics"
                  << "Law" << "Public administration" << "Social services; association"  
                  << "Education"  << "Commerce, communications, transport"  << "Customs, etiquette, folklore";
        editor->clear();
        editor->addItems(comboData);
	} else if (categoryValue == "Language") {
        QStringList comboData;
        comboData << "" << "Language" << "Linguistics"  << "English & Old English" << "Germanic languages; German"
                  << "Romance languages; French" << "Italian, Romanian, Rhaeto-Romanic" << "Spanish & Portuguese languages"  
                  << "Italic; Latin"  << "Hellenic languages; Classical Greek"  << "Other languages";
        editor->clear();
        editor->addItems(comboData);
	} else if (categoryValue == "Science") {
        QStringList comboData;
        comboData << "" << "Natural sciences & mathematics" << "Mathematics"  << "Astronomy & allied sciences" << "Physics" 
                  << "Chemistry & allied sciences" << "Earth sciences" << "Paleontology; Paleozoology"  
                  << "Life sciences"  << "Plants"  << "Zoological sciences";
        editor->clear();
        editor->addItems(comboData);		
	} else if (categoryValue == "Technology") {
        QStringList comboData;
        comboData << "" << "Technology (Applied sciences)" << "Medical sciences; Medicine"  << "Engineering & Applied operations"  
                  << "Agriculture" << "Home economics & family living" << "Management & auxiliary services"  
                  << "Chemical engineering"  << "Manufacturing" << "Manufacture for specific uses"  << "Buildings";
        editor->clear();
        editor->addItems(comboData);
	} else if (categoryValue == "Arts and recreation") {
        QStringList comboData;
        comboData << "" << "The arts" << "Civic & landscape art"  << "Architecture" << "Plastic arts; Sculpture" 
                  << "Drawing & decorative arts (textiles)" << "Painting & paintings" << "Graphic arts; Printmaking & prints"  
                  << "Photography & photographs"  << "Music"  << "Recreational & performing arts";
        editor->clear();
        editor->addItems(comboData);
	} else if (categoryValue == "Literature") {
        QStringList comboData;
        comboData << "" << "Literature & rhetoric" << "American literature in English"  << "English & Old English literatures"  << "Literatures of Germanic languages"
                  << "Literatures of Romance languages" << "talian, Romanian, Rhaeto-Romanic" << "Spanish & Portuguese literatures"  
                  << "Italic literatures; Latin"  << "Hellenic literatures; Classical Greek"  << "Literatures of other languages";
        editor->clear();
        editor->addItems(comboData);
	} else if (categoryValue == "History, geography and biography") {
        QStringList comboData;
        comboData << "" << "Geography & history" << "Geography & travel"  << "Biography, genealogy, insignia"  << "History of ancient world"
                  << "General history of Europe" << "General history of Asia; Far East" << "General history of Africa"  
                  << "General history of North America"  << "General history of South America"  << "General history of other areas";
        editor->clear();
        editor->addItems(comboData);
	}
	
	return editor;
}

void SubCategoryDelegate::setEditorData (QWidget *editor, const QModelIndex &index) const
{
	QString value = index.model()->data(index, Qt::EditRole).toString();
	
	QComboBox *comboBox = static_cast<QComboBox*>(editor);
	
	comboBox->setCurrentIndex(comboBox->findText(value));
}

void SubCategoryDelegate::setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
	QComboBox *comboBox = static_cast<QComboBox*>(editor);
	QString value = comboBox->currentText();
		
	model->setData(index, value, Qt::EditRole);
}

void SubCategoryDelegate::updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
    editor->setGeometry(option.rect);
}
